package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import jdk.dynalink.linker.LinkerServices;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user/shoppingCart")
public class ShoppingCatController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @GetMapping("/list")
    public Result<List<ShoppingCart>> list(){
        log.info("list shoppingCart");
        List<ShoppingCart> shoppingCarts = shoppingCartService.listUserShoppingCart();
        return Result.success(shoppingCarts);
    }

    @DeleteMapping("/clean")
    public Result clean(){
        log.info("clean shoppingCart");
        shoppingCartService.cleanUserShoppingCart();
        return Result.success();
    }

    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("add shoppingCartDTO:{}", shoppingCartDTO);
        shoppingCartService.addUserShoppingCart(shoppingCartDTO);
        return Result.success();
    }



}
